package com.isoftstone.merchant.controller.bind;

import com.isoftstone.bank.controller.base.BaseController;
import com.isoftstone.common.Page;
import com.isoftstone.common.Tidings;
import com.isoftstone.merchant.entity.bind.MBind;
import com.isoftstone.merchant.service.bind.BindService;
import com.isoftstone.util.PageData;
import com.isoftstone.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class BindController extends BaseController {

    @Autowired
    BindService bindService;

    /*
    * 统计签约用户数
    * */
    @RequestMapping("merchant/bind/getBindUserNumber")
    @ResponseBody
    public Object getBindUserNumber(Page page){
        Tidings<Object> tidings=new Tidings<Object>();
        PageData pd = this.getPageData();
        String startDate=pd.getString("startDate");//开始时间
        String endDate=pd.getString("endDate");//结束时间
        Date createDate=new Date();
        pd.put("createDate",createDate);//当前时间
        if (StringUtils.isNotBlank(startDate)){
            pd.put("startDate",startDate);
        }
        if(StringUtils.isNotBlank(endDate)){
            pd.put("endDate",endDate);
        }
        String status="1";//1-生效中 0-解约
        pd.put("status",status);
        page.setPd(pd);

        String corpId=this.getUser().getCorpId();
        pd.put("corpId",corpId);
        page.setPd(pd);
        try {
            MBind bind=bindService.getBindUserNumber(page);
            tidings.setT(bind).setPage(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tidings;
    }


    /*
  * 统计总签约用户数
  * */
    @RequestMapping("merchant/bind/getUserNumber")
    @ResponseBody
    public Object getUserNumber(Page page){
        Tidings<Object> tidings=new Tidings<Object>();
        PageData pd = this.getPageData();

        Date createDate=new Date();
        pd.put("createDate",createDate);//当前时间
        String status="1";//1-生效中 0-解约
        pd.put("status",status);
        String corpId=this.getUser().getCorpId();
        pd.put("corpId",corpId);
        page.setPd(pd);
        try {
            Integer number=bindService.getUserNumber(page);
            tidings.setT(number).setPage(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tidings;
    }


    /*
  * 统计今日签约用户数
  * */
    @RequestMapping("merchant/bind/getTodayUserNumber")
    @ResponseBody
    public Object getTodayUserNumber(Page page){
        Tidings<Object> tidings=new Tidings<Object>();
        PageData pd = this.getPageData();

        Date createDate=new Date();
        pd.put("createDate",createDate);//当前时间
        String status="1";//1-生效中 0-解约
        pd.put("status",status);
        String corpId=this.getUser().getCorpId();
        pd.put("corpId",corpId);
        page.setPd(pd);
        try {
            Integer bind=bindService.getTodayUserNumber(page);
            tidings.setT(bind).setPage(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tidings;
    }
}
